<template>
  <el-row :gutter="40" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" :style="{backgroundImage: img.statistics0, backgroundSize: '100% 100%', backgroundRepeat: 'no-repeat'}" @click="handleSetLineChartData('newVisitis')">
        <div class="card-panel-description">
          <div class="card-panel-count">{{ device_data[0] }}</div>
          <div class="card-panel-text">
            设备总数
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" :style="{backgroundImage: img.statistics1, backgroundSize: '100% 100%', backgroundRepeat: 'no-repeat'}" @click="handleSetLineChartData('messages')">
        <div class="card-panel-description">
          <div class="card-panel-count">{{ device_data[1] }}</div>
          <div class="card-panel-text">
            分配总数
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" :style="{backgroundImage: img.statistics2, backgroundSize: '100% 100%', backgroundRepeat: 'no-repeat'}" @click="handleSetLineChartData('purchases')">
        <div class="card-panel-description">
          <div class="card-panel-count">{{ device_data[2] }}</div>
          <div class="card-panel-text">
            在线总数
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" :style="{backgroundImage: img.statistics3, backgroundSize: '100% 100%', backgroundRepeat: 'no-repeat'}" @click="handleSetLineChartData('shoppings')">
        <div class="card-panel-description">
          <div class="card-panel-count">{{ device_data[3] }}</div>
          <div class="card-panel-text">
            报警总数
          </div>
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import CountTo from 'vue-count-to'

export default {
  // name: 'PanelGroup',
  components: {
    CountTo
  },
  props: {
    device_data: {
      type: Array,
      require: true // 数组长度length 必为4
    }
  },
  data() {
    return {
      img: {
        statistics0: 'url(' + require('../../../assets/img/statistics0.png') + ')',
        statistics1: 'url(' + require('../../../assets/img/statistics1.png') + ')',
        statistics2: 'url(' + require('../../../assets/img/statistics2.png') + ')',
        statistics3: 'url(' + require('../../../assets/img/statistics3.png') + ')'
      }
    }
  },
  methods: {
    handleSetLineChartData(type) {
      this.$emit('handleSetLineChartData', type) // 向外触发,, 影响第二行 折线图展示哪一个数据
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  // margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 100px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    // background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    // border-color: rgba(0, 0, 0, .05);

    .card-panel-description {
      // background-color: aqua;
      float: left;
      font-weight: bold;
      margin: 22px 0 0 22px;
      color: #fff;
      .card-panel-count {
        font-size: 22px;
        margin-bottom: 2px;
      }
      .card-panel-text {
        font-weight: 400;
        font-size: 16px;
      }

    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
